package com.qf.homework.dao.impl;

import com.qf.homework.dao.CategoryDao;
import com.qf.homework.entity.Category;
import com.tomyeung.utils.DBManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class CategoryDaoImpl implements CategoryDao {
    @Override
    public int add(Category category) throws SQLException {
        Connection connection = DBManager.getConnection();
        String sql="insert into hw_category( name, parent_id, img_uri,keyword, description, sor) VALUES (?,?,?,?,?,?)";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1,category.getName());
        ps.setObject(2,category.getParentId());
        ps.setObject(3,category.getImgUri());
        ps.setObject(4,category.getKeyword());
        ps.setObject(5,category.getDescription());
        ps.setObject(6,category.getSort());
        int count = ps.executeUpdate();
        DBManager.close(ps,connection);
        return count;
    }

}
